﻿using UnityEngine;
using System.Collections;

public class DamageNumberFloating : MonoBehaviour {
	
	public float speedY = 1;
	public bool isVisible=false;
	public float countDown=0f;
	public float numberDisplayDuration=0.8f;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if(isVisible){
			if(countDown > 0){
				if(countDown < 0.5f){
					GetComponent<SpriteRenderer>().color = new Color(255f, 255f, 255f, GetComponent<SpriteRenderer>().color.a-(Time.deltaTime*2));
				}
				transform.position = new Vector2(transform.position.x, transform.position.y+(speedY*Time.deltaTime));
				countDown -= Time.deltaTime;
			}else{
				Destroy(this.gameObject);
				isVisible = false;
				GetComponent<SpriteRenderer>().enabled = false;
			}
		}
	}

	public void displayNumber(Vector2 startPosition, Sprite numberSprite){
		transform.position = startPosition;
		GetComponent<SpriteRenderer>().enabled = true;
		GetComponent<SpriteRenderer>().color = new Color(255f, 255f, 255f, 1f);
		GetComponent<SpriteRenderer>().sprite = numberSprite;

		isVisible = true;
		countDown = numberDisplayDuration;
	}
}
